<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/11/26
 * Time: 20:49
 */

class GetClassInfo_model extends MY_Model
{
    function get_class_info($body)
    {
//        var_dump($body);
        $body = json_decode($body);
        $type = $body->type;
        $sql = /** @lang text */
            "SELECT b.`name` AS gradeId,c.`name` AS classId,COUNT(*) AS count,status,COUNT(DISTINCT gradeId) FROM ws_class_$type AS a LEFT JOIN ws_dict_grade AS b ON a.`gradeId`=b.`id` LEFT JOIN ws_dict_class AS c ON a.`classId`=c.`id` GROUP BY gradeId ORDER BY gradeId";
        $query = $this->db->query($sql);
//        var_dump($query->result_array());
        $data = array('count' => 0, 'data' => array(), 'return' => SUCCESS);
        foreach ($query->result_array() as $item => $value) {
            $gd = array();
            $gd['grade'] = $value['gradeId'];
            $gd['class'] = $value['classId'];
            $gd['count'] = $value['count'];
            $gd['s'] = $value['status'];
            array_push($data['data'], $gd);
            $data['count'] += $item;
        }
        return json_encode($data);
    }
}